<?php
/* PHP SDK
 * @version 2.0.0
 * @author connect@qq.com
 * @copyright © 2013, Tencent Corporation. All rights reserved.
 */
namespace zhongkefu\helpers;

use Yii;
use zhongkefu\zhongkefu;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use common\models\Setting\Setting;
use zhongkefu\helpers\ErrorCaseclass;


class Recorderclass{
    private static $data;
    private $inc;
	private $info;
    private $error;

    public function __construct(){
        $this->error = new ErrorCaseclass();

        //-------读取配置文件
	   $this->info = Setting::findBySql('SELECT value FROM setting where code="qqappid" or code="qqappkey" or code="qqcallback"')->asArray()->all();
	   $str='{"appid":'.$this->info[0]['value'].',"appkey":"'.$this->info[1]['value'].'","callback":"'.$this->info[2]['value'].'","scope":"get_user_info,add_t,del_t,get_info","errorReport":true,"storageType":"file"}';
	   $this->inc = json_decode($str);
        if(empty($this->inc)){
            $this->error->showError("20001");
        }

        if(empty(Yii::$app->session['QC_userData'])){
            self::$data = array();
        }else{
            self::$data = Yii::$app->session['QC_userData'];
        }
    }

    public function write($name,$value){
        self::$data[$name] = $value;
    }

    public function read($name){
        if(empty(self::$data[$name])){
            return null;
        }else{
            return self::$data[$name];
        }
    }

    public function readInc($name){
        if(empty($this->inc->$name)){
            return null;
        }else{
            return $this->inc->$name;
        }
    }

    public function delete($name){
        unset(self::$data[$name]);
    }

    function __destruct(){
        Yii::$app->session['QC_userData'] = self::$data;
    }
}
